package com.atguigu.gmall.product.service.impl;

import com.alibaba.fastjson.JSON;
import com.atguigu.gmall.product.vo.SkuSaleAttrValueVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.gmall.product.entity.SpuSaleAttr;
import com.atguigu.gmall.product.service.SpuSaleAttrService;
import com.atguigu.gmall.product.mapper.SpuSaleAttrMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* @author weiranyi
* @description 针对表【spu_sale_attr(spu销售属性)】的数据库操作Service实现
* @createDate 2022-11-29 16:41:29
*/
@Service
public class SpuSaleAttrServiceImpl extends ServiceImpl<SpuSaleAttrMapper, SpuSaleAttr>
    implements SpuSaleAttrService{
    @Autowired
    SpuSaleAttrMapper spuSaleAttrMapper;
    @Override
    public List<SpuSaleAttr> getSpuSaleAttrListOrder(Long spuId,Long skuId) {
        List<SpuSaleAttr> spuSaleAttrs = baseMapper.getSpuSaleAttrListOrder(spuId,skuId);
        return spuSaleAttrs;
    }

    @Override
    public String getvaluesSkuJson(Long spuId) {
        List<SkuSaleAttrValueVo> vos =  spuSaleAttrMapper.getSkuValueJson(spuId);
        Map<String, Long> map = vos.stream().collect(Collectors.toMap((t) -> t.getValueJson(), t -> t.getSkuId()));
        String jsonString = JSON.toJSONString(map);
        return jsonString;
    }
}




